package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.afbx.R;
import com.lc.afbx.adapters.NewsAdapter;
import com.lc.afbx.conn.GetApiInformationIndex;
import com.lc.afbx.fragment.NewsCompanyFragment;
import com.lc.afbx.fragment.NewsOtherFragment;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/31.
 */
public class MoreNewsActivity extends BaseActivity implements View.OnClickListener {

    private TextView more_news_company_tv;
    private TextView more_news_other_tv;

    private TextView left_line;
    private TextView right_line;

    private Fragment[] fragments;
    private NewsCompanyFragment newsCompanyFragment;
    private NewsOtherFragment newsOtherFragment;

    private int index = 0;
    private int prePosition = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_more_news);

        //指示线  绿色的
        left_line = ((TextView) findViewById(R.id.left_line));
        right_line = ((TextView) findViewById(R.id.right_line));

        //公司新闻、行业新闻
        more_news_company_tv = ((TextView) findViewById(R.id.more_news_company_tv));
        more_news_other_tv = ((TextView) findViewById(R.id.more_news_other_tv));

        newsCompanyFragment = new NewsCompanyFragment();
        newsOtherFragment = new NewsOtherFragment();

        fragments = new Fragment[]{newsCompanyFragment, newsOtherFragment};

        getSupportFragmentManager().beginTransaction().add(R.id.more_news_container_rl, newsCompanyFragment)
                .show(newsCompanyFragment).commit();

        more_news_company_tv.setOnClickListener(this);
        more_news_other_tv.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        FragmentTransaction trx = getSupportFragmentManager().beginTransaction();

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.more_news_company_tv:

                more_news_company_tv.setTextColor(getResources().getColor(R.color.titleColor));
                more_news_other_tv.setTextColor(getResources().getColor(R.color.textcolorHei));
                left_line.setVisibility(View.VISIBLE);
                right_line.setVisibility(View.INVISIBLE);

                index = 0;

                if (index != prePosition) {


                    trx.hide(fragments[prePosition]);

                    if (!fragments[index].isAdded()) {

                        trx.add(R.id.more_news_container_rl, fragments[index]);

                    }

                    trx.show(fragments[index]).commit();

                    prePosition = index;
                }


                return;

            case R.id.more_news_other_tv:

                more_news_company_tv.setTextColor(getResources().getColor(R.color.textcolorHei));
                more_news_other_tv.setTextColor(getResources().getColor(R.color.titleColor));
                left_line.setVisibility(View.INVISIBLE);
                right_line.setVisibility(View.VISIBLE);

                index = 1;

                if (index != prePosition) {

                    trx.hide(fragments[prePosition]);

                    if (!fragments[index].isAdded()) {

                        trx.add(R.id.more_news_container_rl, fragments[index]);

                    }

                    trx.show(fragments[index]).commit();

                    prePosition = index;
                }


                return;
        }


    }


}
